/* eslint valid-jsdoc: "off" */

"use strict";
const path = require("path");
const os = require("os");

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1638256398079_9275";

  // 中间件函数
  config.middleware = ["errorHandler"];
  // 其他配置
  // 错误处理中间件
  config.errorHandler = {
    enable: true,
    match: "",
  };
  // mongoose数据库
  config.mongoose = {
    url: "mongodb://127.0.0.1:27017/vue-admin-v1",
    options: {
      useUnifiedTopology: true,
    },
    // mongoose global plugins, expected a function or an array of function and options
    plugins: [
      // createdPlugin,
      // [
      //   updatedPlugin,
      //   pluginOptions,
      // ],
    ],
  };
  // 安全csrf
  config.security = { csrf: { enable: false } };
  // 文件上传
  config.multipart = {
    whitelist: [".png", ".jpg", ".jpeg"],
    fileSize: "500kb",
    mode: "file",
    tmpdir: path.join(os.tmpdir(), "egg-multipart-tmp", appInfo.name),
    cleanSchedule: {
      // run tmpdir clean job on every day 04:30 am
      // cron style see https://github.com/eggjs/egg-schedule#cron-style-scheduling
      cron: "0 30 4 * * *",
      disable: false,
    },
  };
  // 请求参数验证
  config.validate = {
    // 允许类型转换
    convert: true,
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
